package inter;

import fn.Constant;
import fn.Divide;
import fn.Function;
import fn.Multiply;
import fn.Subtract;
import fn.Variable;

public abstract class Interpolation {

	public abstract Function solve(double[][] array);

	public Function getError(double[][] xy, Function f) {
		long fact = 1;
		Function fn = Constant.ONE;
		double average = 0;
		for (int i = 0; i < xy.length; i++) {
			average += xy[i][0];
			f = f.derivative();
			fn = Multiply.create(fn, Subtract.create(Variable.create(), Constant.create(xy[i][0])));
			fact *= (i + 1);
		}
		f = f.derivative();
		average = average / xy.length;
		return Divide.create(Multiply.create(fn, Constant.create(f.evaluate(average))), Constant.create(fact));
	}

	public abstract String toString();
}
